#pragma once

#include "Business/Market.h"
#include "Business/PendingMarket.h"
#include "Business/ContractMatcher.h"

class MarketStorage
{
public:
	MarketStorage(void){}
	~MarketStorage(void){}

	Market const& Save(Market const& market)
	{
		assert(market.GetContract() >= 0 && market.GetContract()< MAX_MARKET_COUNT);

		m_markets[market.GetContract()] = market;
		return m_markets[market.GetContract()];
	}

	void UpdatePrice(Market const& market)
	{
		int contract = market.GetContract();
		assert(contract >= 0 && contract< MAX_MARKET_COUNT);

		m_markets[contract].UpdatePrice(market);
	}

	void SetSpecialLimitPrice(int contract,int upper, int lower)
	{
		m_markets[contract].SetSpecialUpperLimit(upper);
		m_markets[contract].SetSpecialLowerLimit(lower);
	}

	Market const& GetMarket(int contract) const
	{
		assert(contract >= 0 && contract < MAX_MARKET_COUNT);

		return m_markets[contract];
	}

// 	void UpdatePendingMarket(PendingMarket const& market)
// 	{
// 		assert(market.contract >= 0 && market.contract< MAX_MARKET_COUNT);
// 
// 		return m_pendingMarkets[market.contract].Update(market);
// 	}
// 
// 	PendingMarkets const& GetPendingMarkets(int contract) const
// 	{
// 		assert(contract >= 0 && contract < MAX_MARKET_COUNT);
// 		return m_pendingMarkets[contract];
// 	}
// 
// 	PendingMarket GetBuy1(int contract) const
// 	{
// 		PendingMarkets::PendingMarketMap const& buys = GetPendingMarkets(contract).GetBuys();
// 		PendingMarket result;
// 		result.contract = contract;
// 		result.direction = Direction::BUY;
// 		if (buys.size() > 0)
// 		{
// 			result.price = buys.rbegin()->first;
// 			result.quantity = buys.rbegin()->second;
// 		}
// 		else
// 		{
// 			result.price = 0;
// 			result.quantity = 0;
// 		}
// 		return result;
// 	}
// 
// 	PendingMarket GetSell1(int contract) const
// 	{
// 		PendingMarkets::PendingMarketMap const& sells = GetPendingMarkets(contract).GetSells();
// 		PendingMarket result;
// 		result.contract = contract;
// 		result.direction = Direction::SELL;
// 		if (sells.size() > 0)
// 		{
// 			result.price = sells.begin()->first;
// 			result.quantity = sells.begin()->second;
// 		}
// 		else
// 		{
// 			result.price = 0;
// 			result.quantity = 0;
// 		}
// 		return result;
// 	}

private:

	Market m_markets[MAX_MARKET_COUNT];
// 
// 	PendingMarkets m_pendingMarkets[MAX_MARKET_COUNT];
};
